package com.example.fresheveryday.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.fresheveryday.po.Comment;
import com.example.fresheveryday.po.Log;
import com.example.fresheveryday.po.Viewhistory;
import com.example.fresheveryday.service.ViewhistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ll
 * @since 2023-07-5
 */
@RestController
@RequestMapping("/viewhistory")
public class ViewhistoryController {
    @Autowired
    ViewhistoryService viewhistoryService;
    @RequestMapping("myHistory")
    public IPage<Viewhistory> history(@RequestBody Map map){
//        QueryWrapper wrapper = new QueryWrapper();
//        wrapper.eq("userId",id);
//        return viewhistoryService.list(wrapper);
        String id = map.get("id").toString();

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("userId",id);
        Page<Viewhistory> page = new Page<>();

        page.setCurrent(Integer.valueOf(map.get("pageNo").toString()))
                .setTotal(viewhistoryService.countByConditions(wrapper))
                .setSize(Integer.valueOf(map.get("pageSize").toString()));

        return viewhistoryService.getHis(page,wrapper);

    }
    @RequestMapping("insert")
    public String insert(@RequestBody Viewhistory viewhistory){
        viewhistoryService.save(viewhistory);
        return "success";
    }


}
